package com.jams.goodox.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

import com.jams.goodox.utils.DayUtils;

public class BirthdayDateTimePickerDialog extends AlertDialog implements OnClickListener {
	private BirthdayDateTimePicker mDateTimePicker;
	private OnBirthDateTimeSetListener mOnDateTimeSetListener;
	int year;
	int month;
	int day;
	
	public BirthdayDateTimePickerDialog(Context context, int year, int month, int day) {
		super(context);
		if (year > 0) {
			DayUtils.setYear = year;
		}
		if (month > 0) {
			DayUtils.setMonth = month;
		}
		if (day > 0) {
			DayUtils.setDay = day;
		}
		mDateTimePicker = new BirthdayDateTimePicker(context, 0, DayUtils.setYear, DayUtils.setMonth, DayUtils.setDay);
		setView(mDateTimePicker);
		/*
		 * 实现接口，实现里面的方法
		 */
		mDateTimePicker.setOnYearChangedListener(new BirthdayDateTimePicker.OnYearChangedListener() {
			@Override
			public void onDateTimeChanged(BirthdayDateTimePicker view, int year, int month, int day) {
				setDate(year, month, day);
			}
		});
		
		setButton("确定", this);
		setButton2("取消", (OnClickListener) null);
		setTitle("出生日期");
		setDate(DayUtils.setYear, DayUtils.setMonth, DayUtils.setDay);
	}
	
	private void setDate(int year, int month, int day) {
		this.month = month;
		this.day = day;
		this.year = year;
		setTitle("出生日期: " + DayUtils.getBirthdayEntime(year, month, day));
		
	}
	
	/*
	 * 接口回調控件 秒数z
	 */
	public interface OnBirthDateTimeSetListener {
		void OnDateTimeSet(AlertDialog dialog, int year, int month, int day);
	}
	
	/*
	 * 对外公开方法让Activity实现
	 */
	public void setOnDateTimeSetListener(OnBirthDateTimeSetListener callBack) {
		mOnDateTimeSetListener = callBack;
	}
	
	public void onClick(DialogInterface arg0, int arg1) {
		if (mOnDateTimeSetListener != null) {
			mOnDateTimeSetListener.OnDateTimeSet(this, year, month, day);
		}
	}
}
